package com.cy.pj.sys.web;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalTime;

@Slf4j
public class TimeAccessInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        LocalTime now = LocalTime.now();
        int hour = now.getHour();
        log.info("hour {}", hour);
        if (hour<=6||hour>=22)
            throw new RuntimeException("请在 6~10 点进行访问");
        return true;
    }
}
